<%-- 
    Document   : addProdManager
    Created on : Feb 28, 2012, 10:34:47 PM
    Author     : frances
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="Model.DBConnection"%>
<%@page import="java.sql.*"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link rel="stylesheet" href="../css/foo.css" type="text/css"></link>
        <link rel="stylesheet" type="text/css" href="../css/superfish.css" media="screen">	
        <title>Foobar</title>
        <script type="text/javascript" src="../js/jquery-1.7.1.min.js"></script>
        <script type="text/javascript" src="../js/hoverIntent.js"></script>
        <script type="text/javascript" src="../js/superfish.js"></script>
        <script type="text/javascript" src="../js/registerValidation.js"></script>
        <script type="text/javascript" src="../js/foo.css"></script>
        <script type="text/javascript">

            // initialise plugins
            jQuery(function(){
                jQuery('ul.sf-menu').superfish();
            });
            
            function checkAuth(){
                if(<%=request.getParameter("loginAttempt")%> == false){
                    document.write('<span class="errLog">Authentication failed.</span>');
                }
            }

        </script>
    </head>
    <body class="bg">
        <% if (request.getSession(true).getAttribute("username") == null) {
                response.sendRedirect("../login.jsp");
            }%>
        <script type="text/javascript">checkAuth();</script>
        <br/>

        <div class="hmenu">
            <% if (request.getSession(true).getAttribute("username") == null) {%>
            <p style="font-size: 12px; margin-top: -15px; float: right;">If you're not yet a member, sign up <a href="../signUp.jsp">here!</a> </p>   
            <% }%>
            <img src="../images/head.png" style="float: left; margin-left:20px;"></img>
            <div class="log">
                <% if (request.getSession(true).getAttribute("username") != null) {%>
                <h3>Welcome <%=session.getAttribute("username")%>!</h3>
                <br/>
                <!--                insert stuff-->
                <a href="../LogoutServlet">Log out</a>
                <% } else {%>
                <span style="font-weight: bold;">Log in</span>
                <form method="post" action="../LoginServlet">
                    <label>Username:</label><input type="text" name="username"/><br/>
                    <label>Password:</label><input type="password" name="password"/><br/>
                    <input type="submit" value="Log in" name="submit"/>
                </form>
                <% }%>
            </div>
            <% if (request.getSession(true).getAttribute("username") != null && session.getAttribute("acctype").equals("admin")) {%>
            <ul class="sf-menu">
                <li class="current">
                    <a href="admin.jsp">Home</a>  
                </li>
                <li>
                    <a href="addProdAccnt.jsp">Add Manager</a>
                </li>
                <li>
                    <a href="lockAccount.jsp">Lock/Unlock Account</a>
                </li>
                <li>
                    <a href="viewUserlist.jsp">User List</a>

                </li>
            </ul>
            <%  } else {%>
            <ul class="sf-menu">
                <li class="current">
                    <a href="index.jsp">Home</a>
                </li>
                <li>
                    <a href="#">Products</a>
                    <ul>
                        <li>
                            <a href="#">Book</a>
                        </li>
                        <li>
                            <a href="#">Magazine</a>
                        </li>
                        <li>
                            <a href="#">Audio CD</a>
                        </li>
                        <li>
                            <a href="#">DVD</a>
                        </li>
                    </ul>
                </li>
                <li>
                    <a href="#">Stores</a>
                </li>
                <li>
                    <a href="#">Contact Us</a>
                </li>
                <li>
                    <a>SEARCH FUNCTION HERE</a>
                </li>
            </ul>
            <% }%>
        </div>
        <div class="content">
            <% if (request.getSession(true).getAttribute("username") != null && session.getAttribute("acctype").equals("admin")) {%>
            <b>Welcome to Foobar</b>
            <br/>
            Online bookstore made available for you!<br/>
            <hr /> 

            <font color="red">     <%
                String notif = request.getParameter("notif");
                if (notif == null) {
                    notif = "";
                }
            %>
            <%=notif%></font>

            <center>
                <table width="500" border="0"> 

                    <td style="background-color:silver; width:200px;text-align:top;border-radius:5px;">
                        <img src="../images/head.png" style="float: left;height: 50px;"></img><br><br><br>
                        <hr width="500px"/>
                        <form class="signup2" method="post" action="../CreateAccountServlet">
                            <b><p style="font-family: verdana; font-size: 11px; color: black">Create new Product and Accounting Manager Accounts!</p></b>
                            <h6>
                                *Username should be atleast 6 characters with no special characters.<br/>
                                *Password should be atleast 8 characters. <br/>
                                *All fields are required.
                            </h6>

                            <b><p style="font-family: verdana; font-size: 11px;">
                                    Username:<br>
                                    <input name="username" type="text">
                                    <span class="erMes" id="errorusername"></span><br>

                                    Password:<br>
                                    <input name="password" type="password">
                                    <span class="erMes" id="errorpassword"></span><br>    

                                    Re-type Password:<br>
                                    <input name="retypepassword" type="password" class="in"/> 
                                    <br>
                                <hr width="500px"/>
                                </p></b>

                            <!--                 <b><p style="font-family: verdana; font-size: 13px;">Personal Information</p></b>-->
                            <b><p style="font-family: verdana; font-size: 11px;">
                                    Name:<br>
                                    <input name="fname" type="text" placeholder="First name">
                                    <br><input name="midInit" id ="minitial" type="text" placeholder="M.I.">
                                    <br><input name="lname" id ="sname" type="text" placeholder="Last name">
                                    <span class="erMes" id="errorname"></span><br>

                                    E-mail address:<br>
                                    <input name="email" type="text">
                                    <span class="erMes" id="erroremail"></span><br>            
                                <hr width="500px"/>
                                </p></b>
                            <b><p style="font-family: verdana; font-size: 11px;">
                                    User Type:<br>
                                    <select name="usertype">
                                        <!--                                        <option value="---" SELECTED>-------------------</option>
                                                                                <option value="1">Book Manager</option>
                                                                                <option value="2">Magazine Manager</option>
                                                                                <option value="3">Audio CD Manager</option>
                                                                                <option value="4">DVD Manager</option>
                                                                                <option value="7">Accounting Manager</option>-->
                                                              <option value="---" SELECTED>-------------------</option>
                                        <%
                                            Model.DBConnection db = new DBConnection();
                                            Connection conn = db.getConnection();

                                            Statement stmt2 = conn.createStatement();
                                            ResultSet rs = stmt2.executeQuery("Select * from usertype where AccountTypeRef > 0 AND AccountTypeRef != 6 AND AccountTypeRef != 5");
                                            String AccountType = null;
                                            Integer AccountTypeRef = null;
                                            
                                            while (rs.next()) {
                                            AccountType = rs.getString("AccountType");
                                            AccountTypeRef = rs.getInt("AccountTypeRef");
                                
                                        %>
                                        
                                        <option value="<%=AccountTypeRef%>"><%=AccountType%></option>
                                      <%  } %>
                                    </select>
                                    <span class="erMes" id="errorusertype"></span></p></b>
                            <br>

                            <button type="submit" id="submitButton" onClick="return validateManager(this.form);">Create Account</button>

                        </form>
                    </td>
                </table>
                <% } else {%>
                <h1>Oops! We don't think you're allowed to be here.</h1>
                <span>Please log in with the correct user credentials</span>
                <% }%>
        </div>
    </body>
</html>
